package org.test.ping.config;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.test.ping.task.TaskForPing;

/**
 * @ClassName QuartzConfig
 * @Description TODO
 * @Author JiaLin
 * @Date 2024/11/22 9:46
 */
@Configuration
public class QuartzConfig {
    //定时任务类
    @Bean
    public JobDetail uploadTaskDetail() {
        return JobBuilder.newJob(TaskForPing.class).withIdentity("TaskForPing").storeDurably().build();
    }

    @Bean
    public Trigger uploadTaskTrigger() {
        //设定执行方式
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("*/1 * * * * ?");
        // 返回任务触发器
        return TriggerBuilder.newTrigger().forJob(uploadTaskDetail())
                .withIdentity("TaskForPing")
                .withSchedule(scheduleBuilder)
                .build();
    }
}

